package org.litu.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.litu.app.dao.SysDictMapper;
import org.litu.app.entity.system.SysDict;
import org.litu.app.service.ISysDictService;
import org.litu.base.service.impl.BaseServiceImpl;
import org.litu.core.login.UserInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典服务实现类
 * </p>
 *
 * @author ltgk
 * @since 2018-10-24
 */
@Service
public class SysDictServiceImpl extends BaseServiceImpl<SysDictMapper, SysDict> implements ISysDictService {

    @Override
    public void beforeList(UserInfo user, SysDict entity, String keyword, Map<String, String> params, LambdaQueryWrapper<SysDict> query) {
        super.beforeList(user, entity, keyword, params, query);
        // 默认排序
        query.orderByAsc(SysDict::getSortNum);
        query.eq(SysDict::getDictCode, entity.getDictCode());
        query.and(q -> q.like(SysDict::getCode, keyword).or().like(SysDict::getName, keyword));
    }

    /**
     * 获取字典类型的列表
     *
     * @return
     */
    @Override
    public List<SysDict> listDict() {
        return baseMapper.listDict();
    }
}
